package org.Vancl.Dao.ImpI;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.Vancl.Dao.daliDao;
import org.Vancl.entity.shopping;
import org.Vancl.utils.BaseDao;

public class daliDaoImpI extends BaseDao implements daliDao {

	public List<shopping> getcs(int id, int pageNo, int pageSize) {
		String sql="select * from Shopping where s_mid=? ";
		List<Object> params = new ArrayList<>();
		params.add(id);
		sql+=" LIMIT ?,?";
		int start = (pageNo - 1) * pageSize;
		
		params.add(start);
		params.add(pageSize);
		ResultSet rs=super.executeQuery(sql,params.toArray());
		List<shopping> shoppinglist=new ArrayList<shopping>();
		try {
			while(rs.next()){
				shopping shopping=new shopping();
				shopping.setS_id(rs.getInt("s_id"));
				shopping.setS_images(rs.getString("s_images"));
				shopping.setS_mid(rs.getInt("s_mid"));
				shopping.setS_name(rs.getString("s_name"));
				shopping.setS_price(rs.getString("s_price"));
				shoppinglist.add(shopping);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally{
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return shoppinglist;
	}

	
	public int getcount(int id) {
		String sql="select count(1) c from shopping where s_mid=?";
		ResultSet rs=super.executeQuery(sql,id);
		int totalcount=0;
		try {
			if (rs.next()) {
				totalcount=rs.getInt("c");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally {
			try {
				super.CloseAll(rs, rs.getStatement().getConnection(), rs.getStatement());
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return totalcount;
	}

}
